﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;

namespace Ex02
{

    /// <summary>
    /// Projection Strategies:Anonymous Type,into告诉我想做什么，有几种方法
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            //落地：我怎么做的，方法1：匿名类型
            var names = new[] { "Tom", "Dick", "Harry", "Mary", "Jay" }.AsQueryable();

            var intermediate = from n in names
                               select new
                               {
                                   Original = n,
                                   Vowelless = n.Replace("a", "").Replace("e", "").Replace("i", "").Replace("o", "").Replace("u", "")
                               };

            (
                from item in intermediate
                where item.Vowelless.Length > 2
                select item.Original
            )
            .Dump();
            //方法2：into
            // With the into keyword we can do this in one step:

            (
                from n in names
                select new
                {
                    Original = n,
                    Vowelless = n.Replace("a", "").Replace("e", "").Replace("i", "").Replace("o", "").Replace("u", "")
                }
                into temp
                where temp.Vowelless.Length > 2
                select temp.Original
            )
            .Dump("With the 'into' keyword");
            Console.ReadKey();
        }
    }
}
